<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Vue生命周期</title>
</head>
<style class="text/css">
  
</style>
<body>
  
  <div id="app">
    <input type="text" class="input" v-model="mes">
    <button class="addBtn" @click="addItem">添加项目</button>
    <ol type="A">
      <Liitem v-for="(item, index) in arr"
               :key="index"
               :value="item"
               :index="index"
               @delitem="del">
      </Liitem>
    </ol>

    <p>{{mes}}</p>
    <p>{{reve}}</p>
  </div>

  <script type="text/javascript" src="./js/vue.js"></script>
  <script type="text/javascript">

    Vue.component("Liitem", {
      props: ['value', 'index'],
      template: "<li @click='removerItem'>{{ value }} --- {{ index }}</li>",
      methods:{
        removerItem: function(){
          // 自定义事件
          this.$emit("delitem", this.index);
        }
      }
    })

    var app = new Vue({
      el: "#app",
      data: {
        mes: "hello",
        arr: [],
      },
      methods: {
        addItem: function(){
          if(!this.mes){
            return alert("数据不能为空!!");
          }
          this.arr.push(this.mes);
          this.mes = "";
        },

        del: function(res){
          this.arr.splice(res, 1)
        }
      },
      computed: {
        reve:{
          get: function(){
            return this.mes.split('').reverse().join('');
          },

          set: function(val){
           this.mes = val;
          }
         
        }
      },
      // 监听器
      witch: {
        mes: function(){
          console.log("修改了");
        }
      },
      // template:'<div>{{mes}}</div>',
      created: function(){
        console.log("created");
      }
    })
  </script>
</body>
</html>